﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript">
	    //工具栏
	    var toolbar = [{
	        text: '修' +
                '改',
	        iconCls: 'icon-edit',
	        handler: function () {
	            $.ajax({
                    type:"post",
                    url:"/manager/user/findById",
                    data:{"id":$("#booklist").datagrid("getSelected").id},
                    dataType:"json",
                    success:function (result) {
                        if (result.status == 2001) {
                            var user = result.data;
                            $("#name").textbox("setValue",user.username);
                            $("#email").textbox("setValue",user.email);
                            $("#phone").textbox("setValue",user.phone);
                            // $("input[name='phone']").textbox("value",user.phone);
                            $("#message").textbox("setValue",user.interest);
                            $('#dd').dialog('open');
                        }
                    }
                });
            }
	    }, '-', {
	        text: '启用',
	        iconCls: 'icon-ok',
	        handler: function () { 
	            $.ajax({
                    type:"post",
                    url:"/manager/user/modifyStatus",
                    data:{
                        "id":$("#booklist").datagrid("getSelected").id,
                        "status":"1"
                    },
                    dataType:"json",
                    success:function (result) {
                        if (result.status == 2001){
                            $('#booklist').datagrid("reload");
                        }else{
                            alert(result.msg);
                        }
                    }
                });
            }
	    }, '-', {
	        text: '禁用',
	        iconCls: 'icon-cancel',
	        handler: function () {
                $.ajax({
                    type:"post",
                    url:"/manager/user/modifyStatus",
                    data:{
                        "id":$("#booklist").datagrid("getSelected").id,
                        "status":"2"
                    },
                    dataType:"json",
                    success:function (result) {
                        if (result.status == 2001){
                            $('#booklist').datagrid("reload");
                        }else{
                            alert(result.msg);
                        }
                    }
                });

            }
	    }];
	   $(function(){
	       $('#booklist').datagrid({  
				title:'用户列表',  
				iconCls:'icon-save',   
				url:'/manager/user/findByParam',
				columns:[
				    [
					{field:'username',title:'姓名',width:100,align:'center'},
					{field:'phone',title:'电话',width:200,align:'center'},
					{field:'email',title:'eamil',width:80,align:'center'},
					{field:'flag',title:'状态',width:200,align:'center',formatter:function (value,row,index) {
                           return value == 1 ? '启用': '禁用';
                        }}
					]
                ],
				toolbar: toolbar,  
				pagination: true,//表示在datagrid设置分页              
               	pageSize: 5,
				singleSelect:true,
                pageList: [5,10,20]
			});

		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#booklist').datagrid("load",{
                    "username": $("#search_username").val(),
                    "flag" : $("#search_flag").val()
                });   //点击搜索
            });
          
          //初始化修改窗口  
         $('#dd').dialog({
			    title: 'My Dialog',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        $.ajax({
                            type:"post",
                            url:"/manager/user/modifyUser",
                            data:{
                                "id":$("#booklist").datagrid("getSelected").id,
                                "username":$("#name").val(),
                                "email":$("#email").val(),
                                "phone":$("#phone").val(),
                                "interest":$("#message").val()
                            },
                            dataType:"json",
                            success:function (result) {
                                if (result.status == 2001) {
                                    $('#dd').dialog('close');
                                    $('#booklist').datagrid("reload");
                                }
                            }
                        });
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        alert('cancel');;
                    }
                }]
			});
            
	   });
	</script>
</head>
<body>
   <form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>用户查询：</strong></td>
    <td height="30">
        <input type="text" name="username" id="search_username" size=20 placeholder="姓名"/>
        <select name="flag" id="search_flag" >
            <option value="">请选择状态</option>
            <option value="1" >有效</option>
            <option value="2">无效</option>
        </select>
    </td>
	<td>
	  <a id="submit_search">搜索</a>
	</td>
  </form>
  <table id="booklist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox"  id="name" name="name" style="width:50%" data-options="label:'姓名:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="email" name="email" style="width:50%" data-options="label:'email:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="phone" name="phone" style="width:50%" data-options="label:'电话:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="message" name="message" style="width:50%;height:60px" data-options="label:'兴趣爱好:',multiline:true">
            </div> 
        </form>
           </div>
    </div>
</body>
</html>